1478B - Nezzar and Lucky Number - CodeForces Solution


brute force dp greedy math *1100

Please click on ads to support us..

Python Code:

from math import *
from sys import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq

input =stdin.readline

inp = lambda  : int(input())
li  = lambda  : list(map(int,input().split()))
lb  = lambda  : list(map(int,input().split()[0]))
ls  = lambda  : list(input())
bi  = lambda n: bin(n).replace("0b", "")
yn  = lambda f: print('NYOE S'[f::2])
srp = lambda s,i,c : s[:i]+c+s[i+1:]

'''def isprime(a):
    if a==2: return True
    elif a%2==0: return False
    n=3
    while n<=a**0.5:
        if a%n==0:
            return False
        n+=2
    return True
'''
'''def nf(n,a):
    b=a*a
    c=b*a
    d=c*a
    e=n
    ct=0
    while e%a==0:
        if e%d==0:
            ct+=4
            e=e//d
        if e%c==0:
            ct+=3
            e=e//c
        if e%b==0:
            ct+=2
            e=e//b
        if e%a==0:
            ct+=1
            e=e//a
    return ct

t='abcdefghijklmnopqrstuvwxyz'
'''
def ss(s,a):
    return str(a) in str(s)

def solve(__=1):
    for _ in range(__):
        q,d=li()
        a=li()
        for e in a:
            if ss(e,d):
                print("YES")
            else:
                while not ss(e,d) and e>0:
                    e-=d
                yn(e>0)

        



if __name__ == "__main__":
        solve(inp())

C++ Code:

// Problem: B. Nezzar and Lucky Number
// Contest: Codeforces - Codeforces Round 698 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1478/B
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int main()
{	
	fast();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		for(int i=0;i<n;i++)
		{
			int a;
			cin>>a;
			if(a>=10*k)
			{
				yes
				continue;
			}
			bool f=0;
			while(a>0)
			{
				a-=k;
				if(a%10==0)
				{
					f=1;
					break;
				}
				
			}
			if(f)
				yes
				else
				no
		}
	}
}


Comments

Submit
0 Comments
More Questions

1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves